package com.lanou.moving.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lanou.moving.R;
import com.lanou.moving.entity.SearchMvRoot;

import java.util.List;

import it.sephiroth.android.library.picasso.Picasso;

/**
 * Created by dllo on 15/10/26.
 */
public class SearchMvAdapter extends BaseAdapter {
    private Context mcontext;
    private List<SearchMvRoot.DataEntity> data;
    private SearchMvRoot.DataEntity entity;

    public SearchMvAdapter(Context context, List<SearchMvRoot.DataEntity> datas) {
        mcontext = context;
        data = datas;
    }


    @Override
    public int getCount() {
        return data != null && data.size() > 0 ? data.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return data != null && data.size() > 0 ? data.get(position) : null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mcontext).inflate(R.layout.search_mv_content, null);
            holder = new ViewHolder();
            holder.mv_author= (TextView) convertView.findViewById(R.id.mv_author);
            holder.comment_num= (TextView) convertView.findViewById(R.id.comment_num);
            holder.mv_name= (TextView) convertView.findViewById(R.id.mv_name);
            holder.mv_num= (TextView) convertView.findViewById(R.id.mv_num);
            holder.mv_img= (ImageView) convertView.findViewById(R.id.mv_img);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();

        }
        entity=(SearchMvRoot.DataEntity)getItem(position);
        if (entity!=null){
            holder.mv_author.setText(entity.getSingerName());
            holder.comment_num.setText(entity.getBulletCount()+"");
            holder.mv_num.setText(entity.getPickCount()+"");
            holder.mv_name.setText(entity.getVideoName());
            Picasso.with(mcontext).load(entity.getPicUrl()).into(holder.mv_img);
        }


        return convertView;
    }

    private class ViewHolder {
        private ImageView mv_img;
        private TextView mv_name, mv_author, mv_num, comment_num;
    }

}
